package fr.lelouet.ga.stoppers;

import fr.lelouet.ga.Generation;
import fr.lelouet.ga.Stopper;

/**
 * A {@link Stopper} that tells an algorithm to stop after a given time is
 * passed
 * @author le louet
 */
public class MaxTimeStopper<T> implements Stopper<T> {

  protected long restartTimeMillis;

  protected long delayMillis;

  public MaxTimeStopper(long delayMillis) {
    this.delayMillis = delayMillis;
  }

  @Override
  public void restart() {
    restartTimeMillis = System.currentTimeMillis();
  }

  @Override
  public boolean stop(Generation<T> generation) {
    return System.currentTimeMillis() - restartTimeMillis > delayMillis;
  }

}
